package com.ship.dispatch.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ship.dispatch.bean.IshShipBaseExtend;
import com.ship.dispatch.mapper.ShipBaseExtendMapper;
import com.ship.dispatch.service.ShipBaseExtendService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <b>ShipBaseExtendServiceImpl</b>
 *
 * @description: ShipBaseExtendServiceImpl <br>
 * @date: 2024/6/13 18:38 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Service
public class ShipBaseExtendServiceImpl extends ServiceImpl<ShipBaseExtendMapper, IshShipBaseExtend> implements ShipBaseExtendService {

    private static final Logger logger = LoggerFactory.getLogger(ShipBaseExtendServiceImpl.class);

    @Override
    public boolean createShipBaseExtend(Map<String, List<IshShipBaseExtend>> map) {
        if (CollectionUtil.isNotEmpty(map)){
            //删除所有数据
            baseMapper.deleteAll();
            List<IshShipBaseExtend> newShipList = map.get("newShipList");
            boolean b = this.saveBatch(newShipList);
            List<IshShipBaseExtend> operationShipList = map.get("operationShipList");
            boolean b1 = this.saveBatch(operationShipList);
            if (b && b1){
                return true;
            }
        }
        return false;
    }

    @Override
    public IshShipBaseExtend queryShipMessageInteriorByImo(String imo) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("imo",imo);
        queryWrapper.eq("data_type","2");
        queryWrapper.eq("enable","1");
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public PageInfo<IshShipBaseExtend> queryUnderConstructionPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<IshShipBaseExtend> list = baseMapper.queryShipBaseExtendList();
        PageInfo<IshShipBaseExtend> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
